package com.zz.springboot.controller;

import com.zz.springboot.resp.RespTemplate;
import com.zz.springboot.resp.vo.ClassifyStatisticsInfo;
import com.zz.springboot.resp.vo.ProfitAnalysisInfo;
import com.zz.springboot.service.AnalyseService;
import com.zz.springboot.util.DataDealUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@Slf4j
public class AnalyseController {

    @Autowired
    AnalyseService analyseService;

    /**
     * 数据分析接口
     */
    @RequiresRoles(value = {"member", "admin"},logical = Logical.OR)
    @RequestMapping("/dataAnalyse/{type}")
    public RespTemplate<List<ClassifyStatisticsInfo>> dataAnalyse(@PathVariable("type") Integer type) {
        List<ClassifyStatisticsInfo> res = new ArrayList<>();
        res.addAll(analyseService.oddsEvensAnalyse(type));
        res.addAll(analyseService.bigLittleAnalyse(type));
        res.addAll(analyseService.colorsAnalyse(type));
        res.addAll(analyseService.animalsAnalyse(type));
        res.addAll(analyseService.tailsAnalyse(type));

        return RespTemplate.success(res);
    }
    @RequiresRoles(value = {"member", "admin"},logical = Logical.OR)
    @RequestMapping("/oddsEvensAnalyse/{type}")
    public RespTemplate<List<ClassifyStatisticsInfo>> oddsEvensAnalyse(@PathVariable("type") Integer type) {

        List<ClassifyStatisticsInfo> res = analyseService.oddsEvensAnalyse(type);

        return RespTemplate.success(res);
    }
    @RequiresRoles(value = {"member", "admin"},logical = Logical.OR)
    @RequestMapping("/bigLittleAnalyse/{type}")
    public RespTemplate<List<ClassifyStatisticsInfo>> bigLittleAnalyse(@PathVariable("type") Integer type) {

        List<ClassifyStatisticsInfo> res = analyseService.bigLittleAnalyse(type);
        return RespTemplate.success(res);
    }
    @RequiresRoles(value = {"member", "admin"},logical = Logical.OR)
    @RequestMapping("/colorAnalyse/{type}")
    public RespTemplate<List<ClassifyStatisticsInfo>> colorAnalyse(@PathVariable("type") Integer type) {

        List<ClassifyStatisticsInfo> res = analyseService.colorsAnalyse(type);
        return RespTemplate.success(res);
    }
    @RequiresRoles(value = {"member", "admin"},logical = Logical.OR)
    @RequestMapping("/animalsAnalyse/{type}")
    public RespTemplate<List<ClassifyStatisticsInfo>> animalsAnalyse(@PathVariable("type") Integer type) {

        List<ClassifyStatisticsInfo> res = analyseService.animalsAnalyse(type);
        return RespTemplate.success(res);
    }

    @RequiresRoles(value = {"member", "admin"},logical = Logical.OR)
    @RequestMapping("/tailAnalyse/{type}")
    public RespTemplate<List<ClassifyStatisticsInfo>> tailAnalyse(@PathVariable("type") Integer type) {

        List<ClassifyStatisticsInfo> res = analyseService.tailsAnalyse(type);
        return RespTemplate.success(res);
    }
    @RequestMapping("/profitAnalyse/{type}")
    public RespTemplate<String> profitAnalyse(@PathVariable("type") Integer type) {
        ProfitAnalysisInfo info = analyseService.profitAnalyse(type);
        String str = "买入总金额：" + info.getBuyTotalMoney() + "，" +
                "报出总金额：" + info.getExcludeTotalMoney() + "，" +
                "消化总金额：" + info.getEatTotalMoneys() + "，" +
                "设定单个号码最大金额：" + info.getSetSingleMaxEatMoney() + "，" +
                "实际单个号码最大消化金额：" + info.getPracticalSingleMaxEatMoney() + "，" +
                "当前最大亏损约：" + info.getCurrentMaxLossMoney() + "，" +
                "实际单个号码最小消化金额：" + info.getPracticalSingleMinEatMoney() + "，" +
                "当前最大盈利损约：" + info.getCurrentMaxEarnMoney() + "，" +
                "盈利的单个号码极限金额约：" + info.getEarnSingleLimitedEatMoney() + "，" +
                "会产生亏损的号码" + info.getLossNums()  + "，" +
                "亏钱概率约为"+ DataDealUtils.keepPoint((float)(info.getLossNums().size()*100/49.0)) +"%。";
        return RespTemplate.success(str);
    }


}



